﻿using HCQ2_Common;
using HCQ2_Common.Constant;
using HCQ2_Model;
using HCQ2_Model.APIBase;
using HCQ2_Model.ViewModel.WebAPI;
using HCQ2_Model.VRDD.InputDto._210908;
using HCQ2_Model.VRDD.OutputDto._210908;
using HCQ2UI_Helper.Session;
using HCQ2WebAPI_Logic.BaseAPIController;
using HCQ2WebAPI_Logic.Model;
using System;
using System.Collections.Generic;
using System.IO;
using System.Web;
using System.Web.Http;

namespace HCQ2WebAPI_Logic.DocumentController
{
    /// <summary>
    ///  VR度度圈店铺字典
    /// </summary>
    public class VRDDShopController : BaseWeiXinApiLogic
    {
        //****************************************************2021-09-08需求*******************************************************
        #region 1.1 ✔保存店铺数据字典类别 + WebApiResultJsonModel SaveStoreDictType(InputStoreDict param)
        /// <summary>
        ///  1.1 ✔保存店铺数据字典类别
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel SaveStoreDictType(InputStoreDict param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            var dict = operateContext.bllSession.T_VRDDStoreDictType.FindSingle(s => s.store_id == param.storeID && s.dictType.Equals(param.dictType) && s.dictCode.Equals(param.dictCode));
            if (param.type > 0)
            {
                #region 新增
                int sCount = 1;
                if (dict == null)
                    sCount = operateContext.bllSession.T_VRDDStoreDictType.Add(new T_VRDDStoreDictType
                    {
                        store_id = param.storeID,
                        dictCode = param.dictCode,
                        dictType = param.dictType,
                        create_date = DateTime.Now
                    });
                if (sCount > 0)
                    return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "店铺数据字典类别新增成功！", "");
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "店铺数据字典类别新增失败！", "");
                #endregion
            }
            else
            {
                #region 删除
                if (dict == null)
                    return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "待删除的店铺数据字典类别不存在！", "");
                var sCount = operateContext.bllSession.T_VRDDStoreTypeUser.SelectCount(s => s.store_id == param.storeID && s.store_type.Equals(param.dictCode));
                if (sCount > 0)
                    return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "该类别已设置人员，不可删除！", "");
                sCount = operateContext.bllSession.T_VRDDStoreDictType.Delete(s => s.id == dict.id);
                if (sCount > 0)
                    return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "店铺数据字典类别删除成功！", "");
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "店铺数据字典类别删除失败！", "");
                #endregion
            }
        }
        #endregion

        #region 1.2 ✔获取店铺数据字典类别列表 + WebApiResultJsonModel GetDictTypeByStore(InputStoreDictType param)
        /// <summary>
        ///  1.2 ✔获取店铺数据字典类别列表
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel<List<OutputStoreDictType>> GetDictTypeByStore(InputStoreDictType param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel<List<OutputStoreDictType>>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            var list = operateContext.bllSession.T_VRDDStoreTypeUser.GetDictTypeByStore(param);
            return ApiResultJsonModel<List<OutputStoreDictType>>.RedirectWebApi(WebResultCode.Ok, "成功获取店铺数据字典类别列表！", list);
        }
        #endregion

        #region 1.3 ✔获取人员详情 + WebApiResultJsonModel GetStoreUserInfo(InputStoreUserInfo param)
        /// <summary>
        ///  1.3 ✔获取人员详情
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        /// <remarks>
        /// 1、需求变更： 禅道id：237 日期：【2021-11-23】<br/>
        /// </remarks>
        [HttpPost]
        public WebApiResultJsonModel<List<OutputStoreUserInfo>> GetStoreUserInfo(InputStoreUserInfo param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel<List<OutputStoreUserInfo>>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            var list = operateContext.bllSession.T_VRDDStoreTypeUser.GetStoreUserInfo(param);
            return ApiResultJsonModel<List<OutputStoreUserInfo>>.RedirectWebApi(WebResultCode.Ok, "成功获取人员详情！", list);
        }
        #endregion

        #region 1.4 ✔新增店铺类别人员 + WebApiResultJsonModel AddStoreTypeUser(InputStoreTypeUser param)
        /// <summary>
        ///  1.4 ✔新增店铺类别人员
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel AddStoreTypeUser(InputStoreTypeUser param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            foreach (UserList s in param.userList)
            {
                int user_id = SysPermissSession.ChangeIdByGuid(s.userID);
                if (user_id <= 0)
                    return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, $"用户【{s.userID}】非字符串用户内部编码请检查！", "");
                var mark = operateContext.bllSession.T_VRDDStoreTypeUser.SelectCount(o => o.store_id == param.storeID && o.dd_id == user_id && o.store_type.Equals(s.dictCode));
                string folderPath = operateContext.bllSession.T_DocumentFolder.FindSingle(o => o.folder_id == param.storeID)?.folder_path;
                if (mark <= 0)
                    operateContext.bllSession.T_VRDDStoreTypeUser.Add(new T_VRDDStoreTypeUser
                    {
                        store_id = param.storeID,
                        store_path = folderPath,
                        dd_id = user_id,
                        store_type = s.dictCode,
                        store_code = s.dictType,
                        create_date = DateTime.Now
                    });
            }
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "成功新增店铺类别人员！", "");
        }
        #endregion

        #region 1.5 ✔获取店铺类别人员列表 + WebApiResultJsonModel GetStoreTypeUser(InputGetStoreTypeUser param)
        /// <summary>
        ///  1.5 ✔获取店铺类别人员列表
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel<List<OutputGetStoreTypeUser>> GetStoreTypeUser(InputGetStoreTypeUser param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel<List<OutputGetStoreTypeUser>>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            var list = operateContext.bllSession.T_VRDDStoreTypeUser.GetStoreTypeUser(param);
            return ApiResultJsonModel<List<OutputGetStoreTypeUser>>.RedirectWebApi(WebResultCode.Ok, "成功获取店铺类别人员列表！", list);
        }
        #endregion

        #region 1.6 ✔删除店铺人员 + WebApiResultJsonModel DeleteStoreTypeUser(InputDStoreTypeUser param)
        /// <summary>
        ///  1.6 ✔删除店铺人员
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel DeleteStoreTypeUser(InputDStoreTypeUser param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            int user_id = SysPermissSession.ChangeIdByGuid(param.userID);
            var obj = operateContext.bllSession.T_VRDDStoreTypeUser.FindSingle(s => s.store_id == param.storeID && s.dd_id == user_id && s.store_type.Equals(param.dictCode) && s.store_code.Equals(param.dictType));
            if (obj == null)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "待删除的店铺人员已被删除或不存在！", null);
            int mark = operateContext.bllSession.T_VRDDStoreTypeUser.Delete(s => s.id == obj.id);
            if (mark > 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "成功删除店铺人员！", "");
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "删除店铺人员失败！", null);
        }
        #endregion

        #region 1.7 ✔获取店铺商品列表 + WebApiResultJsonModel GetStoreGoodList(InputStoreGoodList param)
        /// <summary>
        ///  1.7 ✔获取店铺商品列表
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel<List<OutputStoreGoodList>> GetStoreGoodList(InputStoreGoodList param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel<List<OutputStoreGoodList>>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            var list = operateContext.bllSession.T_VRDDStoreTypeUser.GetStoreGoodList(param);
            return ApiResultJsonModel<List<OutputStoreGoodList>>.RedirectWebApi(WebResultCode.Ok, "成功获取店铺商品列表！", list);
        }
        #endregion

        #region 1.8 ✔获取商品规格列表 + WebApiResultJsonModel GetGoodSpecList(InputGoodSpec param)
        /// <summary>
        ///  1.8 ✔获取商品规格列表
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel<List<OutputGoodSpec>> GetGoodSpecList(InputGoodSpec param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel<List<OutputGoodSpec>>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            List<OutputGoodSpec> list = new List<OutputGoodSpec>();
            var result = operateContext.bllSession.T_VRDDGoodSpecification.Select(s => s.file_id == param.fileID);
            result?.ForEach(s => list.Add(new OutputGoodSpec { specID = s.id, specName = s.specName, specOption = s.specOption }));
            return ApiResultJsonModel<List<OutputGoodSpec>>.RedirectWebApi(WebResultCode.Ok, "成功获取商品规格列表！", list);
        }
        #endregion

        #region 1.9 ✔删除商品规格 + WebApiResultJsonModel DeleteGoodSpec(DeleteGoodSpec param)
        /// <summary>
        ///  1.9 ✔删除商品规格
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel DeleteGoodSpec(DeleteGoodSpec param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            int mark = operateContext.bllSession.T_VRDDGoodSpecification.SelectCount(s => s.id == param.specID);
            if (mark <= 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "规格id不存在！", null);
            mark = operateContext.bllSession.T_VRDDGoodSpecification.Delete(s => s.id == param.specID);
            if (mark > 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "成功删除商品规格！", "");
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "删除商品规格失败！", null);
        }
        #endregion

        #region 1.10 ✔新增商品规格 + WebApiResultJsonModel AddGoodSpec(AddGoodSpec param)
        /// <summary>
        ///  1.10 ✔新增商品规格
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel AddGoodSpec(AddGoodSpec param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            int mark = operateContext.bllSession.T_DocumentInfo.SelectCount(s => s.file_id == param.fileID && !s.if_remove && s.file_status == 5);
            if (mark <= 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "当前商品id后端不存在！", null);
            var obj = operateContext.bllSession.T_VRDDGoodSpecification.FindSingle(s => s.file_id == param.fileID && s.specName.Equals(param.specName));
            if (!string.IsNullOrEmpty(param.specOption))
                param.specOption = param.specOption.Replace("，", ",");
            if (obj != null)
                mark = operateContext.bllSession.T_VRDDGoodSpecification.Modify(new T_VRDDGoodSpecification { specOption = param.specOption, update_date = DateTime.Now }, s => s.id == obj.id, "specOption", "update_date");
            else
                mark = operateContext.bllSession.T_VRDDGoodSpecification.Add(new T_VRDDGoodSpecification
                {
                    file_id = param.fileID,
                    specName = param.specName,
                    specOption = param.specOption.Replace(";", ",").Replace("，", ",").Replace("；", ","),
                    create_date = DateTime.Now,
                    update_date = DateTime.Now
                });
            if (mark > 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "成功新增商品规格！", "");
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "新增商品规格失败！", null);
        }
        #endregion

        #region 1.11 ✔判断是否店铺的某个人员类型(厨师、服务员或管理员) + WebApiResultJsonModel CheckUserTypeByStore(InputCheckUserType param)
        /// <summary>
        ///  1.11 ✔判断是否店铺的某个人员类型(厨师、服务员或管理员)
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        /// <remarks>
        /// 1、需求变更： 禅道id：233 日期：【2021-11-21】<br/>
        /// </remarks>
        [HttpPost]
        public WebApiResultJsonModel<bool?> CheckUserTypeByStore(InputCheckUserType param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel<bool?>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            int user_id = SysPermissSession.ChangeIdByGuid(param.userid);
            int mark = operateContext.bllSession.T_DocumentFolder.SelectCount(s => s.folder_id == param.storeID);
            if (mark <= 0)
                return ApiResultJsonModel<bool?>.RedirectWebApi(WebResultCode.Exception, "指定店铺id不存在或已被删除！", null);
            mark = operateContext.bllSession.T_VRDDStoreTypeUser.SelectCount(s => s.store_id == param.storeID && s.dd_id == user_id && s.store_code.Equals(param.dictType) && s.store_type.Equals(param.dictCode));
            return ApiResultJsonModel<bool?>.RedirectWebApi(WebResultCode.Ok, "！", mark > 0 ? true : false);
        }
        #endregion

        //****************************************************2021-09-10需求*******************************************************
        #region 2.1 ✔获取商品类别目录 + WebApiResultJsonModel GetGoodsFolderType(InputFolderType param)
        /// <summary>
        ///  2.1 ✔获取商品类别目录
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel<List<OutputFolderType>> GetGoodsFolderType(InputFolderType param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel<List<OutputFolderType>>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            var list = operateContext.bllSession.T_VRDDStoreTypeUser.GetGoodsFolderType(param);
            return ApiResultJsonModel<List<OutputFolderType>>.RedirectWebApi(WebResultCode.Ok, "成功获取商品类别目录！", list);
        }
        #endregion

        #region 2.2 ✔新增商品类别目录 + WebApiResultJsonModel AddGoodsFolderType(InputAddFolderType param)
        /// <summary>
        ///  2.2 ✔新增商品类别目录
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel<int?> AddGoodsFolderType(InputAddFolderType param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel<int?>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            var u = operateContext.bllSession.T_User.FindSingle(s => s.user_guid.Equals(param.UserID));
            if (u == null)
                return ApiResultJsonModel<int?>.RedirectWebApi(WebResultCode.Exception, "用户编码无效！", null);
            //判断目录下是否占用此名称
            int mark = operateContext.bllSession.T_DocumentFolder.SelectCount(s => s.folder_pid == param.FolderPid && s.folder_name.Equals(param.FolderName));
            if (mark > 0)
                return ApiResultJsonModel<int?>.RedirectWebApi(WebResultCode.Exception, "相同FolderPid下，目录名称不能重复！", null);
            var folder = new T_DocumentFolder
            {
                folder_pid = param.FolderPid,
                folder_name = param.FolderName,
                folder_note = param.FolderNote,
                folder_order = param.FolderOrder,
                create_id = u.user_id,
                create_name = u.user_name,
                create_time = DateTime.Now,
                update_name = u.user_name,
                update_date = DateTime.Now,
                if_sys = true,
                if_limit = false,
                if_create_child = true,
                is_share = false,
                if_private = false,
                was_share = false,
                group_name = "type",
                page_type = "DDCircle",
                pro_type = 5,
                doc_type = 3,
                langCode = Helper.GetGuid
            };
            mark = operateContext.bllSession.T_DocumentFolder.Add(folder);
            if (mark > 0)
                return ApiResultJsonModel<int?>.RedirectWebApi(WebResultCode.Ok, "成功新增商品类别目录！", folder.folder_id);
            return ApiResultJsonModel<int?>.RedirectWebApi(WebResultCode.Exception, "新增商品类别目录失败！", null);
        }
        #endregion

        #region 2.3 ✔编辑商品类别目录 + WebApiResultJsonModel EditGoodsFolderType(InputEditFolderType param)
        /// <summary>
        ///  2.3 ✔编辑商品类别目录
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel EditGoodsFolderType(InputEditFolderType param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            var u = operateContext.bllSession.T_User.FindSingle(s => s.user_guid.Equals(param.UserID));
            if (u == null)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "用户编码无效！", null);
            //判断目录下是否占用此名称
            var folder = operateContext.bllSession.T_DocumentFolder.FindSingle(s => s.folder_id == param.FolderID);
            if (folder == null)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, $"查无此【folder={param.FolderID}】！", null);
            int mark = operateContext.bllSession.T_DocumentFolder.SelectCount(s => s.folder_pid == folder.folder_pid && s.folder_id != folder.folder_id && s.folder_name.Equals(param.FolderName));
            if (mark > 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "相同FolderPid下，目录名称不能重复！", null);
            mark = operateContext.bllSession.T_DocumentFolder.Modify(new T_DocumentFolder
            {
                folder_name = param.FolderName,
                folder_note = param.FolderNote,
                folder_order = param.FolderOrder,
                update_name = u.user_name,
                update_date = DateTime.Now
            }, s => s.folder_id == param.FolderID, "folder_name", "folder_note", "folder_order", "update_name", "update_date");
            if (mark > 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "成功编辑商品类别目录！", null);
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "编辑商品类别目录失败！", null);
        }
        #endregion

        #region 2.4 ✔删除商品类别目录 + WebApiResultJsonModel DeleteGoodsFolderType(FolderTypeModel param)
        /// <summary>
        ///  2.4 ✔删除商品类别目录
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel DeleteGoodsFolderType(FolderTypeModel param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            //1.1 判断当前是否有子目录
            int mark = operateContext.bllSession.T_DocumentFolder.SelectCount(s => s.folder_pid == param.FolderID && !s.if_remove);
            if (mark > 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "当前目录下存在未被删除的子目录！", null);
            //1.2 判断当前目录下是否有商品
            if (operateContext.bllSession.T_VRDDStoreTypeUser.GetGoodsFolderTypeNum(param.FolderID))
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "当前目录有已上架商品不允许删除！", null);
            mark = operateContext.bllSession.T_DocumentFolder.Modify(new T_DocumentFolder { if_remove = true }, s => s.folder_id == param.FolderID, "if_remove");
            if (mark > 0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "成功删除商品类别目录！", null);
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "删除商品类别目录失败！", null);
        }
        #endregion

        #region 2.5 ✔获取我服务的店铺 + WebApiResultJsonModel GetStoreByMyServe(InputByMyServe param)
        /// <summary>
        ///  2.5 ✔获取我服务的店铺
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel<List<OutputByMyServe>> GetStoreByMyServe(InputByMyServe param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel<List<OutputByMyServe>>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            int user_id = SysPermissSession.ChangeIdByGuid(param.UserID);
            if (user_id <= 0)
                return ApiResultJsonModel<List<OutputByMyServe>>.RedirectWebApi(WebResultCode.Exception, "用户编码信息无效！", null);
            var list = operateContext.bllSession.T_VRDDStoreTypeUser.GetStoreByMyServe(param, user_id);
            return ApiResultJsonModel<List<OutputByMyServe>>.RedirectWebApi(WebResultCode.Ok, "成功获取我服务的店铺！", list);
        }
        #endregion

        //****************************************************2022-03-24需求*******************************************************
        #region 3.0 ✔保存店铺动态 + WebApiResultJsonModel SaveStoreNews(StoreNewsInput param)
        /// <summary>
        ///  3.0 ✔保存店铺动态
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        /// <remarks>
        /// 20220623 度度圈需求 3.4 
        /// </remarks>
        [HttpPost]
        public WebApiResultJsonModel<int?> SaveStoreNews(StoreNewsInput param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel<int?>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            //1.0 判断商品是否存在
            if (param.fileID > 0)
            {
                var fileCount = operateContext.bllSession.T_DocumentInfo.SelectCount(s => s.file_id == param.fileID && !s.if_remove && s.file_status == 5);
                if (fileCount <= 0)
                    return ApiResultJsonModel<int?>.RedirectWebApi(WebResultCode.Exception, "当前商品被下架或已删除！", null);
            }
            //1.1、验证店铺是否正确
            var storeName = operateContext.bllSession.T_DocumentFolder.FindSingle(s => s.folder_id == param.storeID)?.folder_name;
            if (string.IsNullOrEmpty(storeName))
                return ApiResultJsonModel<int?>.RedirectWebApi(WebResultCode.Exception, "当前店铺不存在！", null);
            //1.2、验证用户是否合法
            var user = operateContext.bllSession.T_User.FindSingle(s => s.user_guid.Equals(param.userid));
            var owner = operateContext.bllSession.T_User.FindSingle(s => s.user_guid.Equals(param.ownerID));
            if (user == null || owner == null)
                return ApiResultJsonModel<int?>.RedirectWebApi(WebResultCode.Exception, "用户信息异常！", null);
            var dy = new T_VRDDStoreDynamic
            {
                storeID = param.storeID,
                store_name = storeName,
                ownerID = param.ownerID,
                owner_id = owner.user_id,
                video_url = param.videoUrl,
                picture_url = param.imageUrl,
                fileID = param.fileID,
                isFeed = param.isFeed > 0 ? true : false,
                gpsX = param.gpsX,
                gpsY = param.gpsY,
                locationName = param.locationName,
                userid = param.userid,
                user_id = user.user_id,
                create_name = user.user_name,
                create_date = DateTime.Now,
                note = param.note
            };
            int mark = operateContext.bllSession.T_VRDDStoreDynamic.Add(dy);
            if(mark<=0)
                return ApiResultJsonModel<int?>.RedirectWebApi(WebResultCode.Exception, "保存店铺动态失败！", null);
            //获取积分来源【汇总表】对应的数据
            var ssmInfo = operateContext.bllSession.T_VRScoreSourceMain.FindSingle(o => o.userid.Equals(param.userid) && o.itemType.Equals("PostVideo") && o.proType.Equals("VCircle"));
            decimal inScore = 1,//收入
                totalScore = 1;//余额
            if (null != ssmInfo)
            {
                inScore = ssmInfo.inScore + 1;
                totalScore = ssmInfo.totalScore + 1;
            }
            //保存明细
            mark = operateContext.bllSession.T_VRScoreSourceDetail.Add(new T_VRScoreSourceDetail
            {
                logCode = Helper.GetGuid,
                userid = user.user_guid,
                user_id = user.user_id,
                user_name = user.user_name,
                itemType = "PostVideo",
                inScore = 1,//本次得分收入
                outScore = 0,
                totalScore = totalScore,//总余额
                proType = "VCircle",
                createDate = DateTime.Now,
                scoreNote = "发布视频"
            });
            //更新积分来源汇总
            if (mark > 0)
            {
                if (null != ssmInfo)
                    operateContext.bllSession.T_VRScoreSourceMain.Modify(new T_VRScoreSourceMain { inScore = inScore, totalScore = totalScore, updateDate = DateTime.Now }, s => s.logCode.Equals(ssmInfo.logCode), "inScore", "totalScore", "updateDate");
                else
                    operateContext.bllSession.T_VRScoreSourceMain.Add(new T_VRScoreSourceMain
                    {
                        logCode = Helper.GetGuid,
                        userid = user.user_guid,
                        user_id = user.user_id,
                        user_name = user.user_name,
                        itemType = "PostVideo",
                        proType = "VCircle",
                        inScore = inScore,
                        outScore = 0,
                        totalScore = totalScore,
                        scoreNote = "发布视频",
                        createDate = DateTime.Now,
                        updateDate = DateTime.Now
                    });
            }
            return ApiResultJsonModel<int?>.RedirectWebApi(WebResultCode.Ok, "保存店铺动态成功！", dy.id);
        }
        #endregion

        #region 3.1 ✔获取店铺动态 + WebApiResultJsonModel GetStoreNews(GetStoreNewsInput param)
        /// <summary>
        ///  3.1 ✔获取店铺动态
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel<BasePage<GetStoreNewsOutput>> GetStoreNews(GetStoreNewsInput param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel<BasePage<GetStoreNewsOutput>>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            var result = operateContext.bllSession.T_VRDDStoreDynamic.GetStoreNews(param);
            return ApiResultJsonModel<BasePage<GetStoreNewsOutput>>.RedirectWebApi(WebResultCode.Ok, "成功获取店铺动态！", result);
        }
        #endregion

        #region 3.2 ✔获取有动态的日期列表 + WebApiResultJsonModel GetNewsDateList(NewsDateInput param)
        /// <summary>
        ///  3.2 ✔获取有动态的日期列表
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel<List<NewsDateOutput>> GetNewsDateList(NewsDateInput param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel<List<NewsDateOutput>>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            var list = operateContext.bllSession.T_VRDDStoreDynamic.GetNewsDate(param);
            return ApiResultJsonModel<List<NewsDateOutput>>.RedirectWebApi(WebResultCode.Ok, "成功获取有动态的日期列表！", list);
        }
        #endregion

        #region 3.3 ✔删除店铺动态 + WebApiResultJsonModel DeleteStoreNews(DeleteStoreInput param)
        /// <summary>
        ///  3.3 ✔删除店铺动态
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel DeleteStoreNews(DeleteStoreInput param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            var dy = operateContext.bllSession.T_VRDDStoreDynamic.FindSingle(s => s.id == param.newsID);
            if (dy == null)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "待删除的店铺动态不存在！", null);
            string videoUrl = dy.video_url,
                picUrl = dy.picture_url;
            int mark = operateContext.bllSession.T_VRDDStoreDynamic.Delete(s => s.id == dy.id);
            if (mark > 0)
            {
                //删除成功、删除对应动态推荐
                operateContext.bllSession.T_VRDDStoreDynamicPushUser.Delete(s => s.dy_id == dy.id);
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "动态删除成功！", null);
            }
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "动态删除失败！", null);
        }
        #endregion

        //****************************************************2022-03-31需求*******************************************************
        #region 4.0 ✔获取商品规格列表 + WebApiResultJsonModel GetCommSpecList(InputGoodSpec param)
        /// <summary>
        ///  4.0 ✔获取商品规格列表
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel<List<CommSpecOutput>> GetCommSpecList(InputGoodSpec param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel<List<CommSpecOutput>>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            var list = operateContext.bllSession.T_VRDDSpecMain.GetCommSpecOutput(param.fileID);
            return ApiResultJsonModel<List<CommSpecOutput>>.RedirectWebApi(WebResultCode.Ok, "成功获取商品规格列表！", list);
        }
        #endregion

        #region 4.1 ✔获取商品价格 + WebApiResultJsonModel GetCommPrice(CommPriceInput param)
        /// <summary>
        ///  4.1 ✔获取商品价格
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel<decimal?> GetCommPrice(CommPriceInput param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel<decimal?>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            ResultServiceData result = operateContext.bllSession.T_VRDDSpecMain.GetCommPrice(param);
            if (!result.isOk)
                return ApiResultJsonModel<decimal?>.RedirectWebApi(WebResultCode.Exception, result.errMsg, null);
            return ApiResultJsonModel<decimal?>.RedirectWebApi(WebResultCode.Ok, string.IsNullOrEmpty(result.errMsg) ? "成功获取商品价格！" : result.errMsg, Helper.ToDecimal(result.data));
        }
        #endregion

        #region 4.2 ✔获取商品库存 + WebApiResultJsonModel GetCommStock(CommPriceInput param)
        /// <summary>
        ///  4.2 ✔获取商品库存
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel<int?> GetCommStock(CommPriceInput param)
        {
            //1.0 验证数据有效性
            if (!ModelState.IsValid)
                return ApiResultJsonModel<int?>.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            ResultServiceData result = operateContext.bllSession.T_VRDDSpecMain.GetCommStock(param);
            if (!result.isOk)
                return ApiResultJsonModel<int?>.RedirectWebApi(WebResultCode.Exception, result.errMsg, null);
            return ApiResultJsonModel<int?>.RedirectWebApi(WebResultCode.Ok, string.IsNullOrEmpty(result.errMsg) ? "成功获取商品库存！" : result.errMsg, Helper.ToInt(result.data));
        }
        #endregion
    }
}